package cn.shop.base.req;

import cn.shop.utils.constant.Constant;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Min;
import java.time.LocalDateTime;

/**
 * @author : 李一涵
 * @date : Created in 2022-3-15 16:32
 * @description :
 */
@Data
@ToString
@EqualsAndHashCode
public class BaseQueryReq {

	/**
	 * 当前页码
	 */
	@Min(value = 1, message = "页码不能为0")
	private int current;
	/**
	 * 每页记录数
	 */
	@Min(value = 1, message = "每页记录数不能为0")
	private int size;
	/**
	 * 起始时间
	 */
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Constant.DATETIME_FORMAT)
	@DateTimeFormat(pattern = Constant.DATETIME_FORMAT)
	private LocalDateTime startTime;
	/**
	 * 结束时间
	 */
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = Constant.DATETIME_FORMAT)
	@DateTimeFormat(pattern = Constant.DATETIME_FORMAT)
	private LocalDateTime endTime;

	/**
	 *  是否按创建时间排序
	 */
	private int orderByTime;
	/**
	 * 主键
	 */
	private Long id;

	public String gtTime(String column) {
		return "date_format("+ column +",'%Y-%m-%d %H:%i') >= date_format({0},'%Y-%m-%d %H:%i')";
	}

	public String ltTime(String column) {
		return "date_format("+ column +",'%Y-%m-%d %H:%i') <= date_format({0},'%Y-%m-%d %H:%i')";
	}
}
